package com.example.pathtracker.activity

import android.content.Intent
import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.example.pathtracker.databinding.ActivityLoginBinding
import com.example.pathtracker.utils.SPUtils

class LoginActivity : AppCompatActivity() {
    private lateinit var binding: ActivityLoginBinding



    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        binding = ActivityLoginBinding.inflate(layoutInflater)
        setContentView(binding.root)
        // 判断是不是第一次进入
        SPUtils.getBoolean(this, "isFirst", false).let {
            if (it) {
                startActivity(Intent(this, MainActivity::class.java))
                finish()
            }else{
                SPUtils.put(this, "isFirst", true)
        }}

        binding.loginButton.setOnClickListener {
            val username = binding.usernameEditText.text.toString()
            val password = binding.passwordEditText.text.toString()
            if (username == "123" && password == "123") {
                startActivity(Intent(this, MainActivity::class.java))
                finish()
            } else {
                Toast.makeText(this, "账号或密码错误", Toast.LENGTH_SHORT).show()
            }
        }
    }
} 